import { defineStore } from "pinia";
import { reactive } from "vue";

/**
 * 参数一：唯一命名
 * 参数二：回调函数
 * 参数三：配置
 */
export const useUserStore = defineStore('user', () => {
  const userInfo = reactive({
    id:'',
    username: '',
    nickname: '',
    email: '',
    userPic: '',
  })

  // 清空数据
  const clearUserInfo = () => {
    userInfo.username = ''
    userInfo.nickname = ''
    userInfo.email = ''
    userInfo.userPic = ''
  }

  // 保存数据
  const setUserInfo = (user) => {
    userInfo.id = user.id
    userInfo.username = user.username
    userInfo.nickname = user.nickname
    userInfo.email = user.email
    userInfo.userPic = user.userPic
  }

  // 输出信息
  // const printUserInfo = ()=>{
  //   console.log('userInfo.username',userInfo.username)
  //   console.log('userInfo.nickname',userInfo.nickname)
  //   console.log('userInfo.email',userInfo.email)
  // }

  return {
    userInfo,
    clearUserInfo,
    setUserInfo,
    // printUserInfo
  }
},
  // 持久化存储

)